# Definition for a binary tree node.
# class TreeNode:
#     def __init__(self, val=0, left=None, right=None):
#         self.val = val
#         self.left = left
#         self.right = right
class Solution:
    def inorderTraversal(self, root):
        # result = []
        # def dfs(root):
        #     if not root: return
        #     dfs(root.left)
        #     result.append(root.val)
        #     dfs(root.right)

        # dfs(root)
        # return result
        WHITE, GRAY = 0, 1
        result = []
        stack = [(WHITE, root)]
        while stack:
            color, node = stack.pop()
            if not node: continue
            if color == WHITE:
                stack.append((WHITE, node.right))
                stack.append((GRAY, node))
                stack.append((WHITE, node.left))
            else:
                result.append(node.val)
        return result